var Promise = require('bluebird');
var Menu = require('../models/menu');
var menuService = require('../services/menuService');

exports.index = function(req,res){
  res.render('index/index', {
    title: '首页'
  });
};

exports.createTestMenu=function(req,res){
  var _menu = {
    title:"主菜单",		//菜单名称
	  icon:"fa-etsy",	//菜单图标
	  srot:1,	//菜单图标
  };
  var _menu1 = new Menu(_menu);
  _menu1.save(function(err){
    if(err)
      console.log(err);
    else
      res.redirect('/');
  });
};
//ObjectId("583e8859efe01a1160048f15")
exports.createTestSubMenu=function(req,res){
  var _menu = {
    title:"菜单管理",		//菜单名称
    url:'/menu',
	  icon:"fa-circle-o",	//菜单图标
	  srot:1,
    menu:"58490fb7b33f6c48f4856483"
  };
  //_id:ObjectId("5841a45a7c557d257c997980")
  var _menu1 = new Menu(_menu);
  _menu1.save(function(err,_menu){
    if(err)
      console.log(err);
    else{
      var MenuID = _menu.menu;
      if(MenuID){
        Menu.findById(MenuID,function(err,menu){
          if(err)
							console.log(err);
						else{
							menu.menus.push(_menu._id);
							menu.save(function(err,menu){
								res.redirect('/');
							})
						}
        });
      }
    }
  });
}